﻿using System;
using System.Text;
using Entities.DataBase;
using WebService.Service.Transfer;

namespace WebService.Email {

    public class CreateOrderRequestTemplate : BaseTemplate {

        public CreateOrderRequest Request { get; set; }

        public new string Subject {
            get {
                return "新订单 - " + DateTime.Now.ToLongDateString();
            }
        }

        public override string GenerateBody() {
            var customer = Services.Locate<ICustomerRepository>().Get(Request.CustomerId);
            var name = customer.CName;
            var builder = new StringBuilder();

            builder.Append("<strong>" + Name + " 刚刚创建了一个新的订单!</strong>");
            builder.Append("<br/>");
            builder.Append("<strong>客户姓名 : </strong>" + name);
            builder.Append("<br/>");
            builder.Append("<strong>客户电话 ：<strong>" + Request.PhoneNumber);
            builder.Append("<br/>");
            builder.Append("<strong>客户地址 : <strong>");
            builder.Append("<br/>");
            builder.Append(Request.ShippingAddress);
            builder.Append("<br/>");

            Request.OrderItems.ForEach(item => builder.Append("<strong>产品名称 :</strong>"     + item.ProductName + "<br/>"
                                                              + "&nbsp;&nbsp;<strong>销售单价: $</strong>" + item.Price       + "<br/>"
                                                              + "&nbsp;&nbsp;<strong>数量 :</strong>"     + item.Count       + "<br/>"
                                                   ));

            return builder.ToString();
        }

       
    }
}